const { observable, action, toJS ,runInAction} = mobx;
const { message } = antd;
const API = ecodeSDK.imp(API);
class listStore {
    // 选项切换
    @observable optionsValue= "1"

    // 状态切换
    @observable tabSelectedKey= "1"

    // 加载状态
    @observable loading= false

    // tab页信息
    @observable tab = []

    //tab页信息统计条数---可以再次隐藏
    //@observable topTabCount = {}

    //代办列表参数 param 
    @observable param ={
      method: "all",
      officalType: -1,
      hideNoDataTab: false,
      viewScope: "doing",
      complete: 0,
      viewcondition: 5,
      defaultTabVal: 0,
      createdateselect: 0,
      creatertype: 0,
      doingStatus: 0,
      recievedateselect: 0,
      wfstatu: 1,
      actiontype: "splitpage"
    }

    @observable topTab=[
      {
        title: "待办",
        color: "#000000",
        groupid: "todo",
        showcount: true,
        viewcondition: "0",
        moreLink:'/wui/index.html#/main/workflow/listDoing?menuIds=1,13&menuPathIds=1,13&_key=v5mrgw',
        data:{
          conditions:{
            requestlevel:1
          },
          method: "all",
          viewScope: "doing",
          viewcondition: 0,
        
        }
      },{
        title: "已办",
        color: "#000000",
        groupid: "done",
        showcount: true,
        viewcondition: "1",
        moreLink:'/wui/index.html#/main/workflow/listDoing?menuIds=1,13&menuPathIds=1,13&_key=v5mrgw',
        data:{
          method: "all",
          viewScope: "done",
          viewcondition: 12,
         
        }
      },
      {
        title: "办结",
        color: "#000000",
        groupid: "completion ",
        showcount: true,
        viewcondition: "2",
        moreLink:'/wui/index.html#/main/workflow/listDoing?menuIds=1,13&menuPathIds=1,13&_key=v5mrgw',
        data:{
          method: "all",
          viewScope: "done",
          viewcondition: 12,
        }
      },{
        title: "我的请求",
        color: "#000000",
        groupid: "myrequest",
        showcount: true,
        viewcondition: "3",
        moreLink:'/wui/index.html#/main/workflow/listDoing?menuIds=1,13&menuPathIds=1,13&_key=v5mrgw',
        data:{
          method: "all",
          viewScope: "mine",
          viewcondition: 16,
        }
      }
      ,{
        title: "超时",
        color: "#000000",
        groupid: "timeout",
        showcount: true,
        viewcondition: "4",
        moreLink:'/wui/index.html#/main/workflow/listDoing?menuIds=1,13&menuPathIds=1,13&_key=v5mrgw',
        data:{
          method: "all",
          viewScope: "doing",
          viewcondition: 3,
         
        }
      },{
        title: "被退回",
        color: "#000000",
        groupid: "Returned",
        showcount: true,
        viewcondition: "5",
        moreLink:'/wui/index.html#/main/workflow/listDoing?menuIds=1,13&menuPathIds=1,13&_key=v5mrgw',
        data:{
          method: "all",
          viewScope: "doing",
          viewcondition: 7, 
        }
      }
      
    ]

    @observable topTab3=[
      {
        title: "资产管理",
        color: "#000000",
        groupid: "property",   //名称要唯一
        showcount: true,
        viewcondition: "0",     //递增
        moreLink:'',
        data:{
          method: "all",
          viewScope: "doing",
          viewcondition: 0,
          workflowtype:"6",  //流程id，多个逗号分割
          workflowid:"s36"   //流程类型id，多个逗号分割
        }
      },
      {
        title: "采购管理",
        color: "#000000",
        groupid: "procure",
        showcount: true,
        viewcondition: "0",
        moreLink:'',
        data:{
          method: "all",
          viewScope: "doing",
          viewcondition: 0,
          workflowtype:"6",
          workflowid:"36"
        }
      },
      {
        title: "信息技术",
        color: "#000000",
        groupid: "technology",
        showcount: true,
        viewcondition: "0",
        moreLink:'',
        data:{
          method: "all",
          viewScope: "doing",
          viewcondition: 0,
          workflowtype:"6",
          workflowid:"36"
        }
      },
      
    ]    
    //代办列表datas
    @observable datas= []

  
    /**
     * 初始化代办列表
     */
    @action
    doInit = ()=>{
      this.tab=this.topTab;
      this.splitPageKey(this.param)
      //初始化待办数量

      //this.getflowCountaa(this.tab)
       this.getflowCount(this.tab)
     

    }

    /**
     * 选项切换
     */
    @action
    paramChoose = (x,y)=>{
      this.optionsValue=x;
      this.tabSelectedKey=y
      var tab = [];
      if(this.optionsValue=='1'){
        tab = this.topTab
      }else if(this.optionsValue=='2'){
        this.getOfsTabData() 
      }else if(this.optionsValue=='3'){
        tab = this.topTab3
      }
      if(this.optionsValue!='2' ){
        this.tab=tab;
        this.param=tab[this.tabSelectedKey].data;
        this.splitPageKey(tab[this.tabSelectedKey].data)
        this.getflowCount(tab)
      }
    }
    /**
     * 选项切换
     */
    @action
    optionsChoose = (v)=>{
     this.optionsValue=v;
    }
    /**
     * 状态切换
     */
    @action
    tabsChoose = (v)=>{
     this.tabSelectedKey=v;
    }
    /**
     * 加载状态
     */
    @action
    loadState = (v)=>{
     this.loading=v;
    }
    
     /**
      * 加载待办列表
      */
    @action
    splitPageKey = (param) =>{
      var _this = this;
      this.loading=true;
      //获取sessionkey
      API.splitPageKey(param).then(res => {
        let sessionkey = res.sessionkey
        let dataparam = {
          dataKey: sessionkey,
          current: 1,
          sortParams: [],
          pageSize:config.number
        }
        //获取代办列表
        API.datas(dataparam).then(res => {
          let datas = res.datas;
          this.datas = datas;
          _this.loading=false;
        })
      

      })
    }
    
  /**
    * 加载待办数量
    */
  @action
  getflowCount = (param) =>{
    let topTabCount={
    }
    param&&param.map((v,k)=>{
      //获取sessionkey
      API.splitPageKey(v.data).then(res => {
        let sessionkey = res.sessionkey
        API.counts({dataKey:sessionkey}).then(res => {
          let count = res.count;
          topTabCount[v.groupid]=count
          this.topTabCount=topTabCount
        })
      })
    })
  }


  //获取异构待办tab
 @action
    getOfsTabData = () =>{
      API.getOfsTabData().then(res => {
        this.tab=res.topTab 
        this.topTabCount=res.topTabCount  
        this.getOfsToDoList({size:5,syscode:this.tab[this.tabSelectedKey].syscode})
      })
    }


  //获取异构待办list
 @action
    getOfsToDoList = (param) =>{
      var _this = this;
      this.loading=true;
      API.getOfsToDoList(param).then(res => {
        let datas = res;
        this.datas = datas;
        this.loading=false;
      })
    }

     /**
      * 获取特色门户主题
      */
    @action
    splitPageKey2 = (param) =>{
      var _this = this;
      this.loading=true;
       WeaTools.callApi(param.port, 'GET', param.param).then(res => {
        this.datas = res;
        _this.loading=false;
      })
    }
    //移除数组中指定元素
    remove = (arr, item)=> {
      for(var i=arr.length-1;i>=0;i--)
        {
        if(arr[i]==item)
          {
            arr.splice(i,1);
            }
        }
      return arr;
    }
  
}
ecodeSDK.exp(listStore);
